//
//  ImageTableViewModel.m
//  GentlemanAnime
//
//  Created by dlios on 15-6-29.
//  Copyright (c) 2015年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "ImageTableViewModel.h"

@implementation ImageTableViewModel

- (void)dealloc {
    [_Id release];
    [_PicTitle release];
    [_coverImageURL release];
    [_imageCount release];
    [_likeCount release];
    [super dealloc];
}


- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    if ([key isEqualToString:@"title"]) {
        self.PicTitle = value;
    } else if ([key isEqualToString:@"coverImage"]) {
        NSRange range = [value rangeOfString:@"jpg"];
        if (range.length) {
            NSString *str = [value substringToIndex:range.location + 3];
            self.coverImageURL = [NSString stringWithFormat:@"%@?imageView2/1/w/320/h/188",str];
        } else {
            range = [value rangeOfString:@"png"];
            if (range.length) {
                NSString *str = [value substringToIndex:range.location + 3];
                self.coverImageURL = [NSString stringWithFormat:@"%@?imageView2/1/w/320/h/188",str];
            } else {
                range = [value rangeOfString:@"JPG"];
                if (range.length) {
                    NSString *str = [value substringToIndex:range.location + 3];
                    self.coverImageURL = [NSString stringWithFormat:@"%@?imageView2/1/w/320/h/188",str];
                } else {
                    range = [value rangeOfString:@"PNG"];
                    NSString *str = [value substringToIndex:range.location + 3];
                    self.coverImageURL = [NSString stringWithFormat:@"%@?imageView2/1/w/320/h/188",str];
                }
            }
        }
    } else if ([key isEqualToString:@"id"]) {
        self.Id = value;
    } else if ([key isEqualToString:@"count"]) {
        self.imageCount = [NSString stringWithFormat:@"%@",value];
    } else if ([key isEqualToString:@"like"]) {
        self.likeCount = [NSString stringWithFormat:@"%@",value];
    }
        
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.PicTitle forKey:@"title"];
    [aCoder encodeObject:self.coverImageURL forKey:@"coverImage"];
    [aCoder encodeObject:self.Id forKey:@"Id"];
    [aCoder encodeObject:self.imageCount forKey:@"imageCount"];
    [aCoder encodeObject:self.likeCount forKey:@"likeCount"];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self= [super init];
    if (self) {
        self.PicTitle = [aDecoder decodeObjectForKey:@"title"];
        self.coverImageURL = [aDecoder decodeObjectForKey:@"coverImage"];
        self.Id = [aDecoder decodeObjectForKey:@"Id"];
        self.imageCount = [aDecoder decodeObjectForKey:@"imageCount"];
        self.likeCount = [aDecoder decodeObjectForKey:@"likeCount"];
    }
    return self;
}




@end
